package com.dfbz.dao;

import java.util.List;
import java.util.Map;

public class HomeDao extends BaseDao{
    public Map<String, Object> findCount() {
        String sql = "select \n" +
                "(select count(1) from user where DATE_FORMAT(register_time,\"%Y-%m-%d\") = CURRENT_DATE) user_count,\n" +
                "(select count(1) from article where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = CURRENT_DATE) article_count,\n" +
                "(select count(1) from meeting where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = CURRENT_DATE) meeting_count";
        return jdbcTemplate.queryForMap(sql);
    }


    public List<Map<String, Object>> findDetailInfo() {
        String sql = "select\n" +
                "(select count(1) from user where DATE_FORMAT(register_time,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-8)) day8, \n" +
                "(select count(1) from user where DATE_FORMAT(register_time,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-7)) day7,\n" +
                "(select count(1) from user where DATE_FORMAT(register_time,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-4)) day6,\n" +
                "(select count(1) from user where DATE_FORMAT(register_time,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-5)) day5,\n" +
                "(select count(1) from user where DATE_FORMAT(register_time,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-4)) day4,\n" +
                "(select count(1) from user where DATE_FORMAT(register_time,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-3)) day3,\n" +
                "(select count(1) from user where DATE_FORMAT(register_time,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-2)) day2,\n" +
                "(select count(1) from user where DATE_FORMAT(register_time,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-1)) day1,\n" +
                "(select count(1) from user where DATE_FORMAT(register_time,\"%Y-%m-%d\") = CURRENT_DATE) today\n" +
                "union all\n" +
                "select\n" +
                "(select count(1) from article where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-8)) day8, \n" +
                "(select count(1) from article where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-7)) day7,\n" +
                "(select count(1) from article where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-4)) day6,\n" +
                "(select count(1) from article where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-5)) day5,\n" +
                "(select count(1) from article where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-4)) day4,\n" +
                "(select count(1) from article where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-3)) day3,\n" +
                "(select count(1) from article where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-2)) day2,\n" +
                "(select count(1) from article where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-1)) day1,\n" +
                "(select count(1) from article where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = CURRENT_DATE) today\n" +
                "union all\n" +
                "select\n" +
                "(select count(1) from meeting where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-8)) day8, \n" +
                "(select count(1) from meeting where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-7)) day7,\n" +
                "(select count(1) from meeting where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-4)) day6,\n" +
                "(select count(1) from meeting where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-5)) day5,\n" +
                "(select count(1) from meeting where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-4)) day4,\n" +
                "(select count(1) from meeting where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-3)) day3,\n" +
                "(select count(1) from meeting where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-2)) day2,\n" +
                "(select count(1) from meeting where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = ADDDATE(CURRENT_DATE,-1)) day1,\n" +
                "(select count(1) from meeting where DATE_FORMAT(publish_date,\"%Y-%m-%d\") = CURRENT_DATE) today";
        return jdbcTemplate.queryForList(sql);
    }
}
